package com.mine.demos;

import com.mine.reflect.MyAnnotation;
import org.junit.Test;
import org.reflections.ReflectionUtils;
import org.reflections.Reflections;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Set;

/**
 * TODO
 *
 * @author wangtonggui
 * @version 1.0.0
 * @since 2021/09/08 16:27
 */
public class ReflectionsDemos {
  @Test
  public void getTypesAnnotatedWithTest() throws IllegalAccessException, InstantiationException, NoSuchFieldException {
    Reflections reflections = new Reflections("com.mine");
    Set<Class<?>> typesAnnotatedWith = reflections.getTypesAnnotatedWith(MyAnnotation.class);
    for (Class<?> aClass : typesAnnotatedWith) {
      Field id = aClass.getDeclaredField("id");
      Object o = aClass.newInstance();
      id.setAccessible(true);
      id.set(o, 1);
      System.out.println(o);
    }
  }
}
